<!doctype html>
<html lang="en" data-color-mode="dark">
<head>
<meta charset="utf-8">
<title>PM2 备忘清单
 &#x26;  pm2 cheatsheet &#x26;  Quick Reference</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta description="PM2PM2 是一个守护进程管理器，它将帮助您管理和保持您的应用程序在线。PM2 入门非常简单，它以简单直观的 CLI 形式提供


入门，为开发人员分享快速参考备忘单。">
<meta keywords="pm2,reference,Quick,Reference,cheatsheet,cheat,sheet">
<link rel="icon" href="data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20height%3D%221em%22%20width%3D%221em%22%3E%20%3Cpath%20d%3D%22m21.66%2010.44-.98%204.18c-.84%203.61-2.5%205.07-5.62%204.77-.5-.04-1.04-.13-1.62-.27l-1.68-.4c-4.17-.99-5.46-3.05-4.48-7.23l.98-4.19c.2-.85.44-1.59.74-2.2%201.17-2.42%203.16-3.07%206.5-2.28l1.67.39c4.19.98%205.47%203.05%204.49%207.23Z%22%20fill%3D%22%23c9d1d9%22%2F%3E%20%3Cpath%20d%3D%22M15.06%2019.39c-.62.42-1.4.77-2.35%201.08l-1.58.52c-3.97%201.28-6.06.21-7.35-3.76L2.5%2013.28c-1.28-3.97-.22-6.07%203.75-7.35l1.58-.52c.41-.13.8-.24%201.17-.31-.3.61-.54%201.35-.74%202.2l-.98%204.19c-.98%204.18.31%206.24%204.48%207.23l1.68.4c.58.14%201.12.23%201.62.27Zm2.43-8.88c-.06%200-.12-.01-.19-.02l-4.85-1.23a.75.75%200%200%201%20.37-1.45l4.85%201.23a.748.748%200%200%201-.18%201.47Z%22%20fill%3D%22%23228e6c%22%20%2F%3E%20%3Cpath%20d%3D%22M14.56%2013.89c-.06%200-.12-.01-.19-.02l-2.91-.74a.75.75%200%200%201%20.37-1.45l2.91.74c.4.1.64.51.54.91-.08.34-.38.56-.72.56Z%22%20fill%3D%22%23228e6c%22%20%2F%3E%20%3C%2Fsvg%3E" type="image/svg+xml">
<link rel="stylesheet" href="../style/style.css">
<link rel="stylesheet" href="../style/katex.css">
</head>
<body><nav class="header-nav"><div class="max-container"><a href="../index.html" class="logo"><svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" height="1em" width="1em">
  <path d="m21.66 10.44-.98 4.18c-.84 3.61-2.5 5.07-5.62 4.77-.5-.04-1.04-.13-1.62-.27l-1.68-.4c-4.17-.99-5.46-3.05-4.48-7.23l.98-4.19c.2-.85.44-1.59.74-2.2 1.17-2.42 3.16-3.07 6.5-2.28l1.67.39c4.19.98 5.47 3.05 4.49 7.23Z" fill="#c9d1d9"></path>
  <path d="M15.06 19.39c-.62.42-1.4.77-2.35 1.08l-1.58.52c-3.97 1.28-6.06.21-7.35-3.76L2.5 13.28c-1.28-3.97-.22-6.07 3.75-7.35l1.58-.52c.41-.13.8-.24 1.17-.31-.3.61-.54 1.35-.74 2.2l-.98 4.19c-.98 4.18.31 6.24 4.48 7.23l1.68.4c.58.14 1.12.23 1.62.27Zm2.43-8.88c-.06 0-.12-.01-.19-.02l-4.85-1.23a.75.75 0 0 1 .37-1.45l4.85 1.23a.748.748 0 0 1-.18 1.47Z" fill="#228e6c"></path>
  <path d="M14.56 13.89c-.06 0-.12-.01-.19-.02l-2.91-.74a.75.75 0 0 1 .37-1.45l2.91.74c.4.1.64.51.54.91-.08.34-.38.56-.72.56Z" fill="#228e6c"></path>
</svg>
<span class="title">Quick Reference</span></a><div class="menu"><a href="javascript:void(0);" class="searchbtn" id="searchbtn"><svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 18 18">
  <path fill="currentColor" d="M17.71,16.29 L14.31,12.9 C15.4069846,11.5024547 16.0022094,9.77665502 16,8 C16,3.581722 12.418278,0 8,0 C3.581722,0 0,3.581722 0,8 C0,12.418278 3.581722,16 8,16 C9.77665502,16.0022094 11.5024547,15.4069846 12.9,14.31 L16.29,17.71 C16.4777666,17.8993127 16.7333625,18.0057983 17,18.0057983 C17.2666375,18.0057983 17.5222334,17.8993127 17.71,17.71 C17.8993127,17.5222334 18.0057983,17.2666375 18.0057983,17 C18.0057983,16.7333625 17.8993127,16.4777666 17.71,16.29 Z M2,8 C2,4.6862915 4.6862915,2 8,2 C11.3137085,2 14,4.6862915 14,8 C14,11.3137085 11.3137085,14 8,14 C4.6862915,14 2,11.3137085 2,8 Z"></path>
</svg><span>搜索</span><span>⌘K</span></a><a href="https://github.com/jaywcjlove/reference/blob/main/docs/pm2.md" class="" target="__blank"><svg viewBox="0 0 36 36" fill="currentColor" height="1em" width="1em"><path d="m33 6.4-3.7-3.7a1.71 1.71 0 0 0-2.36 0L23.65 6H6a2 2 0 0 0-2 2v22a2 2 0 0 0 2 2h22a2 2 0 0 0 2-2V11.76l3-3a1.67 1.67 0 0 0 0-2.36ZM18.83 20.13l-4.19.93 1-4.15 9.55-9.57 3.23 3.23ZM29.5 9.43 26.27 6.2l1.85-1.85 3.23 3.23Z"></path><path fill="none" d="M0 0h36v36H0z"></path></svg><span>编辑</span></a><button id="darkMode" type="button"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="light" height="1em" width="1em">
  <path d="M6.995 12c0 2.761 2.246 5.007 5.007 5.007s5.007-2.246 5.007-5.007-2.246-5.007-5.007-5.007S6.995 9.239 6.995 12zM11 19h2v3h-2zm0-17h2v3h-2zm-9 9h3v2H2zm17 0h3v2h-3zM5.637 19.778l-1.414-1.414 2.121-2.121 1.414 1.414zM16.242 6.344l2.122-2.122 1.414 1.414-2.122 2.122zM6.344 7.759 4.223 5.637l1.415-1.414 2.12 2.122zm13.434 10.605-1.414 1.414-2.122-2.122 1.414-1.414z"></path>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" class="dark" height="1em" width="1em">
  <path d="M12 11.807A9.002 9.002 0 0 1 10.049 2a9.942 9.942 0 0 0-5.12 2.735c-3.905 3.905-3.905 10.237 0 14.142 3.906 3.906 10.237 3.905 14.143 0a9.946 9.946 0 0 0 2.735-5.119A9.003 9.003 0 0 1 12 11.807z"></path>
</svg>
</button><script src="../js/dark.js?v=1.5.2"></script><a href="https://github.com/jaywcjlove/reference" class="" target="__blank"><svg viewBox="0 0 16 16" fill="currentColor" height="1em" width="1em"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg></a></div></div></nav><div class="wrap h1body-exist max-container"><header class="wrap-header h1wrap"><h1 id="pm2-备忘清单"><svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="currentColor" height="1em" width="1em">
  <path d="M10.43 3.223c-.83 1.386-.906 1.499-1.21 1.81-.633.654-1.417 1.003-2.415 1.074-.187.013-1.265.033-2.702.05-.638.008-.75.011-.766.028-.01.011-.185.274-.39.586l-.37.565.104.005c.056.003.443-.003.858-.011a93.159 93.163 0 0 1 1.335-.019c.572 0 .58 0 .667.03.246.084.393.306.355.533a.504.504 0 0 1-.394.42c-.104.027-.375.034-2.821.075-.426.007-.78.015-.784.02a30.5 30.5 0 0 0-.747 1.145c.004.004.405 0 .893-.007 3.13-.051 5.844-.092 6.6-.1.727-.008.995-.02 1.19-.054.54-.092.954-.297 1.31-.65.253-.252.475-.572.852-1.23.125-.217.262-.45.307-.52l.138-.223c.033-.054.07-.11.082-.125.033-.038.1-.146.14-.23.034-.07.534-.906.75-1.257.15-.242.232-.312.42-.355.26-.06.58.102.653.332.06.188.033.305-.136.59-1.21 2.035-1.65 2.764-1.887 3.123-.672 1.018-1.684 1.564-2.991 1.613-.105.003-.773.015-1.486.026l-2.052.031-1.591.027a1166.545 1166.596 0 0 1-3.102.048c-.502.005-.761.013-.78.022a.723.723 0 0 0-.12.186 2.87 2.87 0 0 0-.285.793.427.427 0 0 1-.039.132c-.024.007-.02.787.003.81a.41.41 0 0 1 .04.135c.057.285.197.616.395.932l.092.147 1.316.008c.724.004 2.597.015 4.164.021 1.692.008 2.914.019 3.01.027.318.026.488.052.75.118a3.374 3.374 0 0 1 1.652.95c.255.264.38.44.941 1.339a188.3 188.3 0 0 1 1.494 2.44c.142.28.05.571-.223.7a.588.588 0 0 1-.518.01c-.145-.072-.152-.08-.9-1.29a85.42 85.42 0 0 0-.512-.822 26.09 26.091 0 0 1-.344-.565c-.37-.62-.588-.93-.82-1.162a2.367 2.367 0 0 0-1.164-.627c-.286-.064-.338-.066-2.328-.077a590.763 590.789 0 0 0-3.215-.014c-.738 0-1.634-.005-1.99-.008-.517-.008-.647-.007-.647.007 0 .008.156.27.348.578l.348.56.332.003c2.407.019 2.53.02 2.619.037.194.04.309.123.386.28a.35.35 0 0 1 .05.212.43.43 0 0 1-.143.342.568.568 0 0 1-.251.142c-.075.022-.142.024-1.214.02-.92-.003-1.134 0-1.126.013a93.7 93.7 0 0 0 .704 1.135c.008.007.592.016 1.508.021 1.23.008 1.527.013 1.673.03 1.105.13 1.942.603 2.573 1.457.117.158.248.366.912 1.44l.466.754h.714c.392 0 .714-.003.714-.007s-.257-.42-.57-.924a493.191 493.213 0 0 1-1.49-2.407 12.643 12.644 0 0 0-.274-.43 2.395 2.395 0 0 0-1.434-.97c-.252-.061-.428-.077-.874-.083-.446-.006-.522-.016-.646-.08a.552.552 0 0 1-.231-.227c-.033-.065-.037-.088-.037-.211 0-.127.003-.145.037-.208a.557.557 0 0 1 .357-.275c.07-.021.13-.024.52-.024.345 0 .48.005.625.024.937.12 1.64.445 2.224 1.027.276.276.397.443.758 1.042.127.209.412.672.636 1.028l1.05 1.686.644 1.04h.905c.722 0 .905-.005.9-.018a23.922 23.923 0 0 0-.24-.39c-.46-.737-.493-.796-.513-.943-.027-.206.118-.419.345-.5a.548.548 0 0 1 .6.134c.064.063.414.61.936 1.465l.156.255.178-.009a3.32 3.32 0 0 0 1.31-.325c.065-.03.125-.056.134-.059a3.149 3.149 0 0 0 1.078-.886 541.326 541.35 0 0 0 2.393-3.65c2.484-3.806 2.433-3.724 2.554-4.086a2.682 2.682 0 0 0-.115-2.016c-.048-.103-.838-1.387-2.263-3.683a536.842 536.866 0 0 0-2.253-3.617 2.936 2.936 0 0 0-1.1-.915 3.19 3.191 0 0 0-.902-.316c-.18-.033-.193-.036-.183-.052.004-.008-.106-.01-.292-.01l-.298.005-.265.44c-.588.98-.643 1.068-.726 1.151a.568.568 0 0 1-.309.169c-.222.04-.496-.093-.59-.287-.03-.057-.033-.084-.033-.204 0-.187-.009-.167.504-1.01a3.41 3.41 0 0 0 .147-.254c0-.007-.29-.012-.71-.012h-.71l-.019.03a441.636 441.636 0 0 1-1.829 3.028c-.21.347-.468.776-.57.953-.231.396-.326.54-.49.744a4.123 4.123 0 0 1-.563.56c-.53.411-1.17.66-1.92.747-.361.042-.884.048-1.072.013a.576.576 0 0 1-.384-.276c-.033-.065-.037-.083-.037-.21 0-.12.004-.147.034-.21a.542.542 0 0 1 .352-.279c.073-.02.16-.027.515-.037.264-.007.485-.02.578-.033a3.15 3.15 0 0 0 .599-.15c.164-.065.396-.19.532-.288a2.87 2.87 0 0 0 .53-.526c.056-.074.325-.509.599-.966.273-.458.8-1.334 1.171-1.947.37-.614.677-1.124.68-1.135.006-.016-.098-.018-.703-.018h-.708l-.622 1.035zm7.036.536c0 .01.005.02.012.022.005.001.101.149.212.327.506.81.692 1.117.72 1.194.036.1.04.231.008.323a.646.646 0 0 1-.24.262.543.543 0 0 1-.657-.088c-.08-.075-.165-.201-.46-.685-.11-.182-.214-.346-.229-.366-.016-.024-.022-.046-.016-.066.01-.031.56-.88.601-.925.027-.03.05-.03.05.003zM16.08 5.896c-.004.007 0 .013.005.016.012.004 1.003 1.593 1.574 2.523.48.778.696 1.127.88 1.413.301.469.413.687.526 1.026.115.342.16.653.147 1.005-.007.24-.03.39-.088.624-.102.4-.325.866-.61 1.278-.09.128-.273.322-.304.322-.01 0-.02.005-.02.012 0 .006-.039.025-.086.04a.633.633 0 0 1-.39-.012.661.661 0 0 1-.294-.283c-.032-.067-.034-.087-.029-.19.007-.14.036-.202.231-.503.25-.385.352-.596.424-.885.124-.49.063-.976-.184-1.46a36.64 36.64 0 0 0-.692-1.138 342.675 342.69 0 0 1-1.16-1.867c-.308-.496-.569-.918-.584-.938-.014-.021-.024-.045-.02-.054.01-.027.59-.907.62-.938.02-.022.03-.026.043-.016.01.008.015.02.01.026zm3.142.909a.59.59 0 0 1 .26.188c.095.117 1.425 2.23 1.911 3.04.28.462.41.75.5 1.103.062.243.086.431.086.689 0 .343-.037.57-.145.897-.126.382-.217.553-.658 1.236-.16.25-.998 1.548-1.858 2.887l-1.862 2.89c-.163.253-.303.47-.31.485-.008.013-.019.023-.027.02a20.635 20.636 0 0 1-.625-1.006c0-.009.012-.033.025-.052a8337.117 8337.482 0 0 1 3.846-5.967c.205-.318.266-.429.343-.62a1.95 1.95 0 0 0 .15-.84c-.014-.316-.077-.54-.254-.894-.13-.266-.255-.476-.562-.95-.125-.193-.269-.42-.319-.504a76.564 76.567 0 0 0-.486-.789c-.764-1.226-.755-1.21-.757-1.35 0-.118.04-.212.128-.307a.67.67 0 0 1 .32-.184.633.633 0 0 1 .294.027zm-4.54 1.215.2.325c1.091 1.747 1.137 1.824 1.247 2.043.461.919.465 1.832.014 2.735-.096.19-.135.255-.767 1.236-.848 1.32-.947 1.47-.974 1.5-.022.022-.025.024-.025.003 0-.012-.533-.881-1.184-1.93a193.219 193.227 0 0 1-1.184-1.918c0-.007.554-.858 1.233-1.892a612.753 612.78 0 0 0 1.314-2.007.706.706 0 0 1 .096-.127c.007 0 .02.014.03.033zm2.437 6.843a.675.675 0 0 1 .277.26.469.469 0 0 1 .041.153c.01.133-.024.21-.264.588a820.264 820.3 0 0 1-1.25 1.954l-.125.194c-.022.04-.026.042-.048.026a29.746 29.747 0 0 1-.605-.97c-.012-.03 1.237-1.975 1.327-2.068a.55.55 0 0 1 .446-.182.436.436 0 0 1 .201.045z"></path>
</svg>
<a aria-hidden="true" tabindex="-1" href="#pm2-备忘清单"><span class="icon icon-link"></span></a>PM2 备忘清单</h1><div class="wrap-body">
<p><a href="https://npmjs.org/package/pm2"><img src="https://img.shields.io/npm/v/pm2.svg?style=flat" alt="NPM version"></a>
<a href="https://www.npmjs.com/package/pm2"><img src="https://img.shields.io/npm/dm/pm2.svg?style=flat" alt="Downloads"></a>
<a href="https://github.com/Unitech/pm2/network/dependents"><img src="https://badgen.net/github/dependents-repo/Unitech/pm2" alt="Repo Dependents"></a>
<a href="https://github.com/Unitech/pm2"><img src="https://badgen.net/badge/icon/Github?icon=github&#x26;label" alt="Github repo"></a></p>
<p style="padding-top: 12px;"><a href="https://pm2.keymetrics.io/">PM2</a> 是一个守护进程管理器，它将帮助您管理和保持您的应用程序在线。PM2 入门非常简单，它以简单直观的 CLI 形式提供</p>
<!--rehype:style=padding-top: 12px;-->
</div></header><div class="menu-tocs"><div class="menu-btn"><svg aria-hidden="true" fill="currentColor" height="1em" width="1em" viewBox="0 0 16 16" version="1.1" data-view-component="true">
  <path fill-rule="evenodd" d="M2 4a1 1 0 100-2 1 1 0 000 2zm3.75-1.5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zM3 8a1 1 0 11-2 0 1 1 0 012 0zm-1 6a1 1 0 100-2 1 1 0 000 2z"></path>
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#入门">入门</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#安装">安装</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#启动应用程序">启动应用程序</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#您可以传递给-cli-的一些选项">您可以传递给 CLI 的一些选项</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#管理流程">管理流程</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#你可以传递而不是-app_name">你可以传递而不是 app_name</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#检查状态日志指标">检查状态、日志、指标</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#集群模式">集群模式</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#生态系统文件">生态系统文件</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#设置启动脚本">设置启动脚本</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#重新启动应用程序更改">重新启动应用程序更改</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#pm2-cheatsheet">PM2 CheatSheet</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pm2-分叉模式">PM2 分叉模式</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pm2-集群模式">PM2 集群模式</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pm2-清单">PM2 清单</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pm2-日志">PM2 日志</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pm2-动作">PM2 动作</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pm2-杂项">PM2 杂项</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#更新-pm2">更新 PM2</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#另见">另见</a></div></div><div class="h1wrap-body"><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="入门"><a aria-hidden="true" tabindex="-1" href="#入门"><span class="icon icon-link"></span></a>入门</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="安装"><a aria-hidden="true" tabindex="-1" href="#安装"><span class="icon icon-link"></span></a>安装</h3><div class="wrap-body">
<p>最新的 PM2 版本可通过 NPM 或 Yarn 安装</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ <span class="token function">npm</span> <span class="token function">install</span> pm2@latest <span class="token parameter variable">-g</span>
</span></code></pre>
<p>或者</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ <span class="token function">yarn</span> global <span class="token function">add</span> pm2
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="启动应用程序"><a aria-hidden="true" tabindex="-1" href="#启动应用程序"><span class="icon icon-link"></span></a>启动应用程序</h3><div class="wrap-body">
<p>启动、守护进程和监视应用程序的最简单方法是使用此命令行</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ pm2 start app.js
</span></code></pre>
<p>或者轻松启动任何其他应用程序</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ pm2 start bashscript.sh
</span><span class="code-line">$ pm2 start python-app.py <span class="token parameter variable">--watch</span>
</span><span class="code-line">$ pm2 start binary-file -- <span class="token parameter variable">--port</span> <span class="token number">1520</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist row-span-3"><div class="wrap-header h3wrap"><h3 id="您可以传递给-cli-的一些选项"><a aria-hidden="true" tabindex="-1" href="#您可以传递给-cli-的一些选项"><span class="icon icon-link"></span></a>您可以传递给 CLI 的一些选项</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-3-->
<p>指定应用名称</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token parameter variable">--name</span> <span class="token operator">&#x3C;</span>app_name<span class="token operator">></span>
</span></code></pre>
<p>文件更改时监视并重新启动应用程序</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token parameter variable">--watch</span>
</span></code></pre>
<p>设置应用重新加载的内存阈值</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">--max-memory-restart <span class="token operator">&#x3C;</span>200MB<span class="token operator">></span>
</span></code></pre>
<p>指定日志文件</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token parameter variable">--log</span> <span class="token operator">&#x3C;</span>log_path<span class="token operator">></span>
</span></code></pre>
<p>将额外的参数传递给脚本</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">-- arg1 arg2 arg3
</span></code></pre>
<p>自动重启之间的延迟</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">--restart-delay <span class="token operator">&#x3C;</span>delay <span class="token keyword">in</span> ms<span class="token operator">></span>
</span></code></pre>
<p>带时间的前缀日志</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token parameter variable">--time</span>
</span></code></pre>
<p>不要自动重启应用程序</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">--no-autorestart
</span></code></pre>
<p>指定 cron 强制重启</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token parameter variable">--cron</span> <span class="token operator">&#x3C;</span>cron_pattern<span class="token operator">></span>
</span></code></pre>
<p>附加到应用程序日志</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">--no-daemon
</span></code></pre>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="管理流程"><a aria-hidden="true" tabindex="-1" href="#管理流程"><span class="icon icon-link"></span></a>管理流程</h3><div class="wrap-body">
<p>管理应用程序状态很简单，这里是命令</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ pm2 restart app_name
</span><span class="code-line">$ pm2 reload app_name
</span><span class="code-line">$ pm2 stop app_name
</span><span class="code-line">$ pm2 delete app_name
</span></code></pre>
<h4 id="你可以传递而不是-app_name"><a aria-hidden="true" tabindex="-1" href="#你可以传递而不是-app_name"><span class="icon icon-link"></span></a>你可以传递而不是 app_name</h4>
<ul>
<li><code>all</code> 作用于所有进程</li>
<li><code>id</code> 作用于特定的进程 ID</li>
</ul>
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="检查状态日志指标"><a aria-hidden="true" tabindex="-1" href="#检查状态日志指标"><span class="icon icon-link"></span></a>检查状态、日志、指标</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<p>现在您已经启动了这个应用程序，您可以检查它的状态、日志、指标，甚至可以使用 <a href="https://pm2.io/">pm2.io</a> 获取在线仪表板</p>
<p>列出PM2管理的所有应用的状态</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ pm2 <span class="token punctuation">[</span>list<span class="token operator">|</span><span class="token function">ls</span><span class="token operator">|</span>status<span class="token punctuation">]</span>
</span></code></pre>
<p>实时显示日志</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ pm2 logs
</span></code></pre>
<p>挖掘旧日志</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ pm2 logs <span class="token parameter variable">--lines</span> <span class="token number">200</span>
</span></code></pre>
<p>这是一个直接适合您的终端的实时仪表板</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ pm2 monit
</span></code></pre>
<p>基于 Web 的仪表板，具有诊断系统的跨服务器</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ pm2 plus
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="集群模式"><a aria-hidden="true" tabindex="-1" href="#集群模式"><span class="icon icon-link"></span></a>集群模式</h3><div class="wrap-body">
<p>对于 Node.js 应用程序，PM2 包括一个自动负载均衡器，它将在每个衍生进程之间共享所有 HTTP[s]/Websocket/TCP/UDP 连接</p>
<p>以集群模式启动应用程序</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ pm2 start app.js <span class="token parameter variable">-i</span> max
</span></code></pre>
<p>在 <a href="https://pm2.keymetrics.io/docs/usage/quick-start/">此处</a> 阅读有关集群模式的更多信息</p>
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="生态系统文件"><a aria-hidden="true" tabindex="-1" href="#生态系统文件"><span class="icon icon-link"></span></a>生态系统文件</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<p>您还可以创建一个称为生态系统文件的配置文件来管理多个应用程序。生成生态系统文件</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ pm2 ecosystem
</span></code></pre>
<p>这将生成一个 <code>ecosystem.config.js</code> 文件</p>
<pre class="language-js"><code class="language-js code-highlight"><span class="code-line">module<span class="token punctuation">.</span><span class="token property-access">exports</span> <span class="token operator">=</span> <span class="token punctuation">{</span>
</span><span class="code-line">  <span class="token literal-property property">apps</span> <span class="token operator">:</span> <span class="token punctuation">[</span><span class="token punctuation">{</span>
</span><span class="code-line">    <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">"app"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token literal-property property">script</span><span class="token operator">:</span> <span class="token string">"./app.js"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token literal-property property">env</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">      <span class="token constant">NODE_ENV</span><span class="token operator">:</span> <span class="token string">"development"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token punctuation">}</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token literal-property property">env_production</span><span class="token operator">:</span> <span class="token punctuation">{</span>
</span><span class="code-line">      <span class="token constant">NODE_ENV</span><span class="token operator">:</span> <span class="token string">"production"</span><span class="token punctuation">,</span>
</span><span class="code-line">    <span class="token punctuation">}</span>
</span><span class="code-line">  <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
</span><span class="code-line">     <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'worker'</span><span class="token punctuation">,</span>
</span><span class="code-line">     <span class="token literal-property property">script</span><span class="token operator">:</span> <span class="token string">'worker.js'</span>
</span><span class="code-line">  <span class="token punctuation">}</span><span class="token punctuation">]</span>
</span><span class="code-line"><span class="token punctuation">}</span>
</span></code></pre>
<p>并轻松启动</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ pm2 start ecosystem.config.js
</span></code></pre>
<p>在 <a href="https://pm2.keymetrics.io/docs/usage/application-declaration/">此处</a> 阅读有关应用程序声明的更多信息</p>
</div></div></div><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="设置启动脚本"><a aria-hidden="true" tabindex="-1" href="#设置启动脚本"><span class="icon icon-link"></span></a>设置启动脚本</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->
<p>使用您在服务器启动/重新启动时管理的进程重新启动 PM2 至关重要。为了解决这个问题，只需运行这个命令来生成一个活动的启动脚本</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ pm2 save
</span></code></pre>
<p>在 <a href="https://pm2.keymetrics.io/docs/usage/startup/">此处</a> 阅读有关启动脚本生成器的更多信息</p>
</div></div></div><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="重新启动应用程序更改"><a aria-hidden="true" tabindex="-1" href="#重新启动应用程序更改"><span class="icon icon-link"></span></a>重新启动应用程序更改</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->
<p>使用 <code>--watch</code> 选项非常简单</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ <span class="token builtin class-name">cd</span> /path/to/my/app
</span><span class="code-line">$ pm2 start env.js <span class="token parameter variable">--watch</span> --ignore-watch<span class="token operator">=</span><span class="token string">"node_modules"</span>
</span></code></pre>
<p>这将在当前目录 <code>+</code> 所有子文件夹中的任何文件更改时监视并重新启动应用程序，并且它将忽略 <code>node_modules</code> 文件夹中的任何更改 <code>--ignore-watch="node_modules"</code>。</p>
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ pm2 logs
</span></code></pre>
<p>然后，您可以使用上面命令来检查重新启动的应用程序日志。</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="pm2-cheatsheet"><a aria-hidden="true" tabindex="-1" href="#pm2-cheatsheet"><span class="icon icon-link"></span></a>PM2 CheatSheet</h2><div class="wrap-body">
<!--rehype:body-class=cols-2-->
<p>以下是一些值得了解的命令。 只需使用示例应用程序或开发机器上当前的 Web 应用程序来尝试它们</p>
</div></div><div class="h2wrap-body cols-2"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="pm2-分叉模式"><a aria-hidden="true" tabindex="-1" href="#pm2-分叉模式"><span class="icon icon-link"></span></a>PM2 分叉模式</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ pm2 start app.js <span class="token parameter variable">--name</span> my-api <span class="token comment"># 名称进程</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="pm2-集群模式"><a aria-hidden="true" tabindex="-1" href="#pm2-集群模式"><span class="icon icon-link"></span></a>PM2 集群模式</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ pm2 start app.js <span class="token parameter variable">-i</span> <span class="token number">0</span>     <span class="token comment"># 将根据可用的 CPU 使用 LB 启动最大进程</span>
</span><span class="code-line">$ pm2 start app.js <span class="token parameter variable">-i</span> max   <span class="token comment"># 与上面相同，但已弃用。</span>
</span><span class="code-line">$ pm2 scale app +3          <span class="token comment"># 将 `app` 增加 3 名工人</span>
</span><span class="code-line">$ pm2 scale app <span class="token number">2</span>           <span class="token comment"># 将 `app` 向上或向下扩展到总共 2 个工人</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="pm2-清单"><a aria-hidden="true" tabindex="-1" href="#pm2-清单"><span class="icon icon-link"></span></a>PM2 清单</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ pm2 list        <span class="token comment"># 显示所有进程状态</span>
</span><span class="code-line">$ pm2 jlist       <span class="token comment"># 以原始 JSON 格式打印进程列表</span>
</span><span class="code-line">$ pm2 prettylist  <span class="token comment"># 以美化JSON打印进程列表</span>
</span><span class="code-line">$ pm2 describe <span class="token number">0</span>  <span class="token comment"># 显示有关特定进程的所有信息</span>
</span><span class="code-line">$ pm2 monit       <span class="token comment"># 监控所有进程</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="pm2-日志"><a aria-hidden="true" tabindex="-1" href="#pm2-日志"><span class="icon icon-link"></span></a>PM2 日志</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ pm2 logs <span class="token punctuation">[</span>--raw<span class="token punctuation">]</span>  <span class="token comment"># 在流中显示所有进程日志</span>
</span><span class="code-line">$ pm2 flush         <span class="token comment"># 清空所有日志文件</span>
</span><span class="code-line">$ pm2 reloadLogs    <span class="token comment"># 重新加载所有日志</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="pm2-动作"><a aria-hidden="true" tabindex="-1" href="#pm2-动作"><span class="icon icon-link"></span></a>PM2 动作</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ pm2 stop all     <span class="token comment"># 停止所有进程</span>
</span><span class="code-line">$ pm2 restart all  <span class="token comment"># 重启所有进程</span>
</span><span class="code-line">$ pm2 reload all   <span class="token comment"># 将 0s 停机时间重新加载（对于 NETWORKED 应用程序）</span>
</span><span class="code-line">$ pm2 stop <span class="token number">0</span>       <span class="token comment"># 停止特定进程 ID</span>
</span><span class="code-line">$ pm2 restart <span class="token number">0</span>    <span class="token comment"># 重启特定进程id</span>
</span><span class="code-line">$ pm2 delete <span class="token number">0</span>     <span class="token comment"># 将从 pm2 列表中删除进程</span>
</span><span class="code-line">$ pm2 delete all   <span class="token comment"># 将从 pm2 列表中删除所有进程</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="pm2-杂项"><a aria-hidden="true" tabindex="-1" href="#pm2-杂项"><span class="icon icon-link"></span></a>PM2 杂项</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ pm2 reset <span class="token operator">&#x3C;</span>process<span class="token operator">></span>    <span class="token comment"># 重置元数据（重启时间...）</span>
</span><span class="code-line">$ pm2 updatePM2          <span class="token comment"># 更新内存 pm2</span>
</span><span class="code-line">$ pm2 <span class="token function">ping</span>               <span class="token comment"># 确保 pm2 守护进程已经启动</span>
</span><span class="code-line">$ pm2 sendSignal SIGUSR2 my-app <span class="token comment"># 向脚本发送系统信号</span>
</span><span class="code-line">$ pm2 start app.js --no-daemon
</span><span class="code-line">$ pm2 start app.js --no-vizion
</span><span class="code-line">$ pm2 start app.js --no-autorestart
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="更新-pm2"><a aria-hidden="true" tabindex="-1" href="#更新-pm2"><span class="icon icon-link"></span></a>更新 PM2</h3><div class="wrap-body">
<p>我们让它变得简单，版本之间没有重大变化，过程很简单</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ <span class="token function">npm</span> <span class="token function">install</span> pm2@latest <span class="token parameter variable">-g</span>
</span></code></pre>
<p>然后更新内存中的PM2</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ pm2 update
</span></code></pre>
</div></div></div></div></div><div class="wrap h2body-not-exist"><div class="wrap-header h2wrap"><h2 id="另见"><a aria-hidden="true" tabindex="-1" href="#另见"><span class="icon icon-link"></span></a>另见</h2><div class="wrap-body">
<ul>
<li><a href="https://pm2.keymetrics.io/docs/usage/quick-start/">QUICK START</a> <em>(pm2.keymetrics.io)</em></li>
</ul>
</div></div><div class="h2wrap-body"></div></div></div><script src="https://giscus.app/client.js" data-repo="jaywcjlove/reference" data-repo-id="R_kgDOID2-Mw" data-category="Q&#x26;A" data-category-id="DIC_kwDOID2-M84CS5wo" data-mapping="pathname" data-strict="0" data-reactions-enabled="1" data-emit-metadata="0" data-input-position="bottom" data-theme="dark" data-lang="zh-CN" crossorigin="anonymous" async></script><div class="giscus"></div></div><footer class="footer-wrap"><footer class="max-container">© 2022 Kenny Wang.</footer></footer><script src="../data.js?v=1.5.2" defer></script><script src="../js/fuse.min.js?v=1.5.2" defer></script><script src="../js/main.js?v=1.5.2" defer></script><div id="mysearch"><div class="mysearch-box"><div class="mysearch-input"><div><svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 18 18">
  <path fill="currentColor" d="M17.71,16.29 L14.31,12.9 C15.4069846,11.5024547 16.0022094,9.77665502 16,8 C16,3.581722 12.418278,0 8,0 C3.581722,0 0,3.581722 0,8 C0,12.418278 3.581722,16 8,16 C9.77665502,16.0022094 11.5024547,15.4069846 12.9,14.31 L16.29,17.71 C16.4777666,17.8993127 16.7333625,18.0057983 17,18.0057983 C17.2666375,18.0057983 17.5222334,17.8993127 17.71,17.71 C17.8993127,17.5222334 18.0057983,17.2666375 18.0057983,17 C18.0057983,16.7333625 17.8993127,16.4777666 17.71,16.29 Z M2,8 C2,4.6862915 4.6862915,2 8,2 C11.3137085,2 14,4.6862915 14,8 C14,11.3137085 11.3137085,14 8,14 C4.6862915,14 2,11.3137085 2,8 Z"></path>
</svg><input id="mysearch-input" type="search" placeholder="搜索" autocomplete="off"><div class="mysearch-clear"></div></div><button id="mysearch-close" type="button">搜索</button></div><div class="mysearch-result"><div id="mysearch-menu"></div><div id="mysearch-content"></div></div></div></div></body>
</html>
